package com.sucker.infoservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sucker.commonutils.R;
import com.sucker.infoservice.entity.Activity;
import com.sucker.infoservice.service.ActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.crypto.hash.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 活动表
 * </p>
 *
 * @author sucker
 * @since 2022-07-04
 */
@Tag(name = "ActivityController",description = "活动管理")
@RestController
@RequestMapping("/infoservice/activity")
@CrossOrigin
public class ActivityController {

    @Autowired
    private ActivityService activityService;


    /**
     * 查询活动
     * @return
     */
    @Operation(summary = "查询活动",description = "详细描述：查询所有活动")
    @GetMapping("queryAll")
    public R queryAll(){
        List<Activity> list = activityService.list();
        return R.ok().data("list",list);
    }


    /**
     * 根据地域查询活动
     * @param region
     * @return
     */
    @Operation(summary = "根据地域查询活动",description = "详细描述：根据地域查询活动")
    @GetMapping("queryByRegion")
    public R queryByRegion(@Parameter(description = "地域") @RequestParam String region){

        List<Activity> activities = activityService.list(new QueryWrapper<Activity>().eq("region", region));
        return R.ok().data("list",activities);

    }


    /**
     * 根据名称查询活动
     * @param name
     * @return
     */
    @Operation(summary = "根据名称查询活动",description = "详细描述：根据名称模糊查询活动")
    @GetMapping("queryByName")
    public R queryByName(@Parameter(description = "名称") @RequestParam String name){

        List<Activity> activities = activityService.list(new QueryWrapper<Activity>().like("ac_name", name));
        return R.ok().data("list",activities);

    }


}

